<!DOCTYPE HTML>
<html xmlns:th="http://www.thymeleaf.org">

<head>
    <th:block th:include="include :: header('首页')" />
</head>
<body>
<th:block th:include="include :: top" />

<div class="col-lg-5 mx-auto p-4 py-md-5">


    <article class="my-3" id="overview">
        <div class="bd-heading sticky-xl-top align-self-start mt-3 mb-3 mt-xl-0 mb-xl-2">
            <h3>登录</h3>
        </div>

        <div>
            <div class="bd-example-snippet bd-code-snippet"><div class="bd-example m-0 border-0">
                <form>
                    <div class="mb-3">
                        <label for="exampleInputEmail1" class="form-label">手机号</label>
                        <input type="email" class="form-control" id="exampleInputEmail1" aria-describedby="emailHelp" value="18077200000">
<!--                        <div id="emailHelp" class="form-text">输入手机号</div>-->
                    </div>
                    <div class="mb-3">
                        <label for="exampleInputPassword1" class="form-label">密码</label>
                        <input type="password" class="form-control" id="exampleInputPassword1" value="123456">
                    </div>

                    <button type="button" class="btn btn-primary" id="exampleBtn">Submit</button>
                </form>
            </div></div>

        </div>
    </article>


</div>
</body>

<th:block th:include="include :: js" />
<script th:inline="javascript">
$(document).ready(function () {
    $("#exampleBtn").on("click", function() {


        var inputPass = $("#exampleInputPassword1").val();
        var salt = "9d5b364d";
        var str = "" + salt.charAt(0) + salt.charAt(2) + inputPass + salt.charAt(5) + salt.charAt(4);
        var password = md5(str);

        var data = {mobile: $("#exampleInputEmail1").val(),password: password};

            $.ajax({
            type: 'POST',
            url: '/login',
            data : JSON.stringify(data),
            dataType: 'json',
            contentType: "application/json; charset=utf-8",
            success: function(data) {
                if (data.code == 200) {
                    Cookies.set("Authorization", data.data, { expires: 1, path: '/' })
                    location.href = document.referrer.endsWith("login")? '/' : document.referrer;
                } else {
                    alert(data.msg);
                }
            },
            error: function() {
                    alert("登录失败");
            }
        });


    });




});
</script>


</html>
